<%
Class aspwebcache_applicationObject_store
	Private urlEncoded

	Public Sub setContent(url, content)
		'Refreshes current resource in cache
		urlEncoded = Server.URLEncode(url)
		Application.Lock'Lock the application object
		Application("aspwebcache_" & urlEncoded) = content'Add content
		Application("aspwebcache_" & urlEncoded + "_ts") = now()'Add cache creation timestamp
		Application.Unlock'Unlock the application object	
	End Sub
	
	Public Function getContent(url)
		urlEncoded = Server.URLEncode(url)
		getContent = Application("aspwebcache_" & urlEncoded)
	End Function
	
	Public Function getAttribute(url, attribute)
		'gets the specified attribute for the url. if the attribute does not exist, it returns blank.
		urlEncoded = Server.URLEncode(url)
		getAttribute = Application("aspwebcache_" & urlEncoded + "_" + attribute)
	End Function
	
	Public Sub removeAll()
		Application.Lock'Lock the application object
		Application.Contents.RemoveAll()'Remove All
		Application.Unlock'Unlock the application object
	End Sub
	
	Public Sub remove(url)
		urlEncoded = Server.URLEncode(url)
		Application.Lock'Lock the application object
		Application.Contents.Remove("aspwebcache_" & urlEncoded)'Remove content
		Application.Contents.Remove("aspwebcache_" & urlEncoded + "_ts")'Remove cache creation timestamp
		Application.Unlock'Unlock the application object
	End Sub
	
	Public Function count()
		'counts the objects in the store
		count = Application.Contents.Count
	End Function
	
	Public Function contents()
		Dim contName, arraySize, arrayPointer
		
		arraySize = Application.Contents.Count/2
		execute("Dim results(" & arraySize & ")")
		arrayPointer = 0
		
		For each x in Application.Contents
			contName = URLDecode(x)
			contName = Right(contName,Len(contName)-12)
			if not right(contName,3)="_ts" then 
				results(arrayPointer) = contName
				arrayPointer = arrayPointer+1
			end if
		Next
		
		contents = results
	End Function
	
	Private Function URLDecode(sConvert)
		'copied from [http://www.aspnut.com/reference/encoding.asp#urldecode], should be rewritten.
		Dim aSplit
		Dim sOutput
		Dim I
		If IsNull(sConvert) Then
		   URLDecode = ""
		   Exit Function
		End If
		
		' convert all pluses to spaces
		sOutput = REPLACE(sConvert, "+", " ")
		
		' next convert %hexdigits to the character
		aSplit = Split(sOutput, "%")
		
		If IsArray(aSplit) Then
		  sOutput = aSplit(0)
		  For I = 0 to UBound(aSplit) - 1
			sOutput = sOutput & _
			  Chr("&H" & Left(aSplit(i + 1), 2)) &_
			  Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
		  Next
		End If
		
		URLDecode = sOutput
	End Function
End Class
%>